//
//  GTVideoCoverViewCell.m
//  news
//
//  Copyright © 2022 sinosun. All rights reserved.
//

#import "GTVideoCoverViewCell.h"
#import "GTVideoPlayer.h"



@interface GTVideoCoverViewCell()

@property (nonatomic, strong, readwrite) UIImageView *coverView;
@property (nonatomic, strong, readwrite) UIImageView *playButton;
@property (nonatomic, strong, readwrite) NSString *videoUrl;



@end

@implementation GTVideoCoverViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:({
            _coverView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
            _coverView;
        })];
        
        [_coverView addSubview:({
            _playButton = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - 50 ) /2 , (frame.size.height - 50 ) /2, 50, 50)];
            _playButton.backgroundColor = [UIColor lightGrayColor];
            _playButton;
        })];
        
        // 为播放按钮添加一个手势
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_tapToPlay)];
        [self addGestureRecognizer:tapGesture];
        

        
    }
    return self;
}

- (void)dealloc
{
    
}
- (void)layoutWithVideoCoverUrl:(NSString *)videoCoverUrl videoUrl:(NSString *)videoUrl{
    _coverView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:videoCoverUrl]]];
    
    _videoUrl = videoUrl;
}

- (void)_tapToPlay{
    [[GTVideoPlayer Player] playVideoWithUrl:_videoUrl attachView:_coverView];
}
@end
